package com.cby.juc.线程.RunnableAndCallable;

/**
 * ClassName: RunnableDemo
 * Package: com.cby.juc.线程.RunnableAndCallable
 * Description:
 *
 * @Author dhu-bion
 * @Create 2025/9/12 16:25
 * @Version 1.0
 */
import java.util.concurrent.*;

public class RunnableDemo {
    // 用成员变量存结果（需线程安全，此处简化）
    private static long result;

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            try {
                // 计算10的阶乘（业务逻辑）
                long sum = 1;
                for (int i = 1; i <= 10; i++) {
                    sum *= i;
                }
                result = sum; // 手动赋值给外部变量
            } catch (Exception e) {
                // 无法抛出，只能内部捕获处理
                e.printStackTrace();
            }
        });

        thread.start();
        thread.join(); // 等待线程执行完
        System.out.println("Runnable结果：" + result); // 输出：3628800
    }
}